import React from 'react'
import { connect } from 'dva'
import { Form, Button, Modal, Popconfirm, Table, Row, Col, Input, Select, Cascader, Icon, Checkbox, DatePicker } from 'antd'
import { Link, hashHistory } from 'dva/router'
import config from 'config/config'
import { mapStateToProps } from 'utils/view_utils'
import styles from './templatesDetailStyle.less'
import ListPage from 'widget/PageTmpl/ListPage'
import classnames from 'classnames/bind';
let cx = classnames.bind(styles);
import FlagBtn from 'widget/FlagBtn/FlagView'
import PriviewForm from 'widget/PriviewForm'
import Cookie from 'js-cookie'

const confirm = Modal.confirm;
const homeBannerListView = function ({ dispatch, model, form }) {
  // 表单的子函数
  const { resetFields, getFieldDecorator, validateFields, setFieldsValue } = form
  // 取出model对象，命名空间
  const { modelObj, namespace } = model
  let { saveData, modalObj, actionType, id,hashUrl,param } = modelObj
  let token = Cookie.get(config.cookie.auth) 
  let url =  `${config.h5Url}formTemplate/index.html`
  if (id) {
    url = `${url}?token=${token}&questionFormId=${id}&hashUrl=${hashUrl}&param=${param}`
  } else {
    url = `${url}?token=${token}&hashUrl=${hashUrl}&param=${param}`
  }
  console.log('aaa',url)

  window.addEventListener("message", receiveMessage, false);
  function receiveMessage(event) {
    if(event.data){
      let query = null;
       if(event.data.query&&event.data.query!=="undefined"){
        query = JSON.parse(decodeURI(event.data.query))
       }
      hashHistory.push({
        pathname: event.data.hashUrl,
        query: query
      });
    }
    
};

  return (

    <div className={cx('pageLayout')}>
      <div style={{ height: (window.screen.height   - 125+'px')}}>
        <iframe
          id="myFrame"
          width="100%"
          height="100%"
          frameBorder={0}
          scrolling="no"
          src={url}
        />
      </div>
    </div>
  )
}
// 连接视图(view)和模型(model)
export default connect(mapStateToProps)(Form.create()(homeBannerListView))
